package com.itheima.jdsearch.controller;

import com.itheima.jdsearch.model.PageResult;
import com.itheima.jdsearch.model.SearchReq;
import com.itheima.jdsearch.pojo.GoodInfo;
import com.itheima.jdsearch.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @作者 itcast
 * @创建日期 2021/5/15 8:48
 **/
@RestController
@RequestMapping("good")
public class SearchController {
    @Autowired
    SearchService searchService;
    // ? key1=value1 & key2=val2
    @GetMapping("search/{page}/{size}")
    public Map search(SearchReq searchReq,
                      @PathVariable Integer page,
                      @PathVariable Integer size){
        Map resultMap = new HashMap();
        List<String> categoryList = searchService.findCategoryListByKeyword(searchReq.getKeyword());
        resultMap.put("categoryList",categoryList);
        PageResult<GoodInfo> pageResult = searchService.findGoodsListByQuery(searchReq, page, size);
        resultMap.put("pageResult",pageResult);
        return resultMap;
    }
}
